﻿// basic.cpp : 定义应用程序的入口点。
//

#include "stdafx.h"
#include "main.h"
#include "layouts_form.h"

enum ThreadId
{
	kThreadUI
};

int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
                     _In_opt_ HINSTANCE hPrevInstance,
                     _In_ LPWSTR    lpCmdLine,
                     _In_ int       nCmdShow)
{
	UNREFERENCED_PARAMETER(hPrevInstance);
	UNREFERENCED_PARAMETER(lpCmdLine);
#ifdef _DEBUG
	AllocConsole();
	FILE* fp = NULL;
	freopen_s(&fp, "CONOUT$", "w+t", stdout);
	wprintf_s(L"Command:\n%s\n\n", L"");
#endif
	// 创建主线程
	MainThread thread;

	// 执行主线程循环
	thread.RunOnCurrentThreadWithLoop(nbase::MessageLoop::kUIMessageLoop);

	return 0;
}

void MainThread::Init()
{
	nbase::ThreadManager::RegisterThread(kThreadUI);
	std::wstring sAppDir = nbase::win32::GetCurrentModuleDirectory();
#ifdef _DEBUG
		ui::GlobalManager::Startup(sAppDir + L"\\resources\\", ui::CreateControlCallback(), false, L"themes", L"lang\\zh_CN", L"public\\global.xml");
#else
	ui::GlobalManager::OpenResZip(sAppDir + L"\\resources\\themes\\themes.zip", "");
	ui::GlobalManager::Startup(L"", ui::CreateControlCallback(), false, L"", L"lang\\zh_CN", L"public\\global.xml");
#endif // DEBUG

	// 一个仿微信的布局示例
	LayoutsForm::ShowCustomWindow(L"basic_layout", L"examples/layouts", L"wechat.xml");

	// 一个仿登录窗口的布局示例
	// LayoutsForm::ShowCustomWindow(L"login", L"layouts", L"login.xml");
}

void MainThread::Cleanup()
{
	ui::GlobalManager::Shutdown();
	SetThreadWasQuitProperly(true);
	nbase::ThreadManager::UnregisterThread();
}
